/*
 * debug_task.c
 *
 *  Created on: 2024年8月15日
 *      Author: nwz
 */

#include <all_header.h>

static uint8_t buffer[512];

void test_flash_write_speed(void) {
	flash_stream_task_set_state(Flash_Stream_Task_State_Open);
	flash_stream_task_set_state(Flash_Stream_Task_State_Erase_Download);

	LOG_SYNC("start test flash write speed" NL);
	uint32_t start_ticks = NOW();
	int tsize = 0;
	const int write_size = sizeof(buffer);
	while (tsize < 1024 * 1024) {
		while (true) {
			if (flash_stream_task_get_avaliabe_size() >= write_size) {
				ASSERT(
						flash_stream_task_write_buffer(buffer, write_size,Flash_Stream_Task_State_Write_Download)
								== write_size);
				break;
			} else {
				flash_stream_task_wait(portMAX_DELAY);
			}
		}
		tsize += write_size;
		uint32_t end = NOW();
		if (end - start_ticks > 0) {
			LOG_SYNC("speed %dkB/s" NL,
					tsize * 1000 / 1024 / (end - start_ticks));
		} else {
			LOG_SYNC("ignore" NL);
		}
	}

	flash_stream_task_set_state(Flash_Stream_Task_State_Close);
}

void test_console_send_recv(void) {
	int size;
	LOG_D("test_console_send_recv" NL);
	while (true) {
		size = console_read_task_read(buffer, sizeof(buffer), portMAX_DELAY);
		console_write_task_write2(buffer, size);
	}
}

extern void *_etext;
extern void *_sidata;
extern void *_sdata;
extern void *_edata;

void test_ld_file_params(void){
	LOG_D("_etext %p" NL, _etext);
	LOG_D("_sidata %p" NL, _sidata);
	LOG_D("_sdata %p" NL, _sdata);
	LOG_D("_edata %p" NL, _edata);
}

void debug_task_run(void *arg) {
	while (true) {
		DELAY(100);
	}
}
